<!--这里是带tab的页面布局，如果想用这种方式直接在layouts/index.js中第三行替换BasicLayoutTab.vue-->
<template>
  <div>
    <a-icon
      type="menu"
      :class="collapsed?'collapsed_style':'uncollapsed_style'"
      style="font-size: 20px;color: #fff;cursor: pointer"
      @click="handleFunction"/>
    <span class="ant-pro-account-avatar" style="float: right">
      <a-avatar size="small" :src="currentUser.imagePath" class="antd-pro-global-header-index-avatar" />
      <span style="margin:0 10px">{{ currentUser.name }}</span>
      <span style="margin:0 10px;cursor: pointer" @click="handleLogout">退出登录</span>
    </span>
  </div>

</template>

<script>
import { getUserThumbAvatar, logout } from '@/api/avatarDropdown'
import storage from 'store'
import { Modal } from 'ant-design-vue'

export default {
  name: 'RightContent',
  data () {
    return {
      showMenu: true,
      currentUser: {}
    }
  },

  props: {
    handleFunction: Function,
    collapsed: Boolean
  },
  // computed: {
  //   wrpCls () {
  //     return {
  //       'ant-pro-global-header-index-right': true,
  //       [`ant-pro-global-header-index-${(this.isMobile || !this.topMenu) ? 'light' : this.theme}`]: true
  //     }
  //   }
  // },
  mounted () {
    getUserThumbAvatar({ userName: storage.get('USERINFO').userInfo.userName.toLowerCase() }).then(res => {
      if (res.retCode === 0) {
        this.currentUser = {
          name: storage.get('USERINFO').userInfo.realName,
          userName: storage.get('USERINFO').userInfo.userName,
          imagePath: res.retObj
        }
      } else {
        this.currentUser = {
          name: storage.get('USERINFO').userInfo.realName,
          userName: storage.get('USERINFO').userInfo.userName,
          imagePath: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
        }
      }
    })
  },
  methods: {
    show () {
      this.$refs.departSelect.show()
    },
    handleLogout (e) {
      Modal.confirm({
        title: '是否确定退出',
        onOk: () => {
          logout().then(res => {
            return this.$store.dispatch('Logout')
          })
        },
        onCancel () {
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.ant-pro-drop-down {
  /deep/ .action {
    margin-right: 8px;
  }

  /deep/ .ant-dropdown-menu-item {
    min-width: 160px;
  }
}

.collapsed_style {
  margin-left: 90px;
}

.uncollapsed_style {
  margin-left: 250px;
}
</style>
